<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>成单客户管理</title>
    <meta name="decorator" content="default"/>
    <link rel="stylesheet" href="${ctxStatic}/bootstrap-table/bootstrap-table.css">
    <script src="${ctxStatic}/bootstrap-table/bootstrap-table.js"></script>
    <script src="${ctxStatic}/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
    <script src="${ctxStatic}/bootstrap-table/config.js"></script>
</head>
<body>
<form id="searchForm" action="${ctx}/customer/potentialAfterSalesService/listAjaxData" method="post"
      class="breadcrumb form-search">
    <ul class="ul-form">
        <ul class="ul-form">
            <li>
                <div class="input-prepend">
                    <span class="add-on">展示状态</span>
                    <select name="onshow" class="select-medium">
                        <option value="">全&nbsp;&nbsp;&nbsp;&nbsp;部</option>
                        <option value="1">展示中</option>
                        <option value="0">不展示</option>
                    </select>
                </div>
                <div class="input-prepend">
                    <span class="add-on">客户类型</span>
                    <sys:customerType name="customerType" cssClass="select-medium" withAll="true"/>
                </div>
                <div class="input-prepend">
                    <span class="add-on">成单产品</span>
                    <sys:productType name="targetproducts" cssClass="select-medium" withAll="true" withWu="true"/>
                </div>
            </li>
            <li>
            <li class="btns">
                <shiro:hasPermission name="customer:potentialAfterSalesService:edit">
                <button id="open" class="btn btn-small btn-info" type="button">
                    展示<span class="icon-eye-open icon-white"></span>
                </button>
                <button id="close" class="btn btn-small btn-info" type="button">
                    取消<span class="icon-eye-close icon-white"></span>
                </button>
                </shiro:hasPermission>
            </li>
            </li>
        </ul>
        <ul class="ul-form">
            <li>
                <div class="input-prepend">
                        <span class="add-on">
                            客户名称
                        </span>
                    <input name="corporationName" type="text" class="input-medium" placeholder="请输入客户名称"/>
                </div>
                <div class="input-prepend">
                    <span class="add-on">开始时间</span>
                    <input readonly="true" name="beginDate" type="text" class="input-medium"
                                onmousedown="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
                </div>
                <div class="input-prepend">
                    <span class="add-on">结束时间</span>
                    <input readonly="true" name="endDate" type="text" class="input-medium"
                                onmousedown="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
                </div>
            </li>
            <li class="btns">
                <button id="search" class="btn btn-small btn-primary" type="button">
                    查询<span class="icon-search icon-white"></span>
                </button>
            </li>
            <li class="clearfix"></li>
        </ul>
    </ul>
</form>
<table id="contentTable" data-url="${ctx}/customer/potentialAfterSalesService/listAjaxData">
    <thead>
    <tr>
        <th data-field="state" data-checkbox="true" data-align="center"></th>
        <th data-field="onshow" data-align="center" data-formatter="onshowFormat">展示状态</th>
        <th data-field="corporationName" data-align="center">
            客户名称
        </th>
        <th data-field="customerType" data-align="center">
            客户类型
        </th>
        <th data-field="customerFeature" data-align="center">
            客户特点
        </th>
        <th data-field="amount" data-align="center">
            成单金额
        </th>
        <th data-field="year" data-align="center">
            成单年限
        </th>
        <th data-field="productName" data-align="center">
            成单产品
        </th>
        <th data-field="dateCreated" data-align="center">
            成单时间
        </th>
        <th data-field="receiver" data-align="center">
            收款人
        </th>
        <th data-field="createUsername" data-align="center">
            成单人
        </th>
        <th data-field="operation" data-align="center" data-formatter="operateFormatter" data-events="operateEvents">
            操作
        </th>
    </tr>
    </thead>
</table>
<script type="text/javascript">
    $(document).ready(function () {
        $("#contentTable").bootstrapTable(
            $.fn.BTConfigSimple({
            pageList: [30, 50, 100],
            pageSize: 30,
            sortName: "a.date_created",
            userQuery:function(){
                return $("#searchForm").refreshByForm().query;
            }
        }));

        $("#search").click(function () {
            refresh();
        });
    });
    //全局函数部分
    function refresh() {
        $("#contentTable").bootstrapTable(
          'refresh',$("#searchForm").refreshByForm());
    }

    function onshowFormat(value) {
        if (value == "1") {
            return "<span style='color: #008000;'><i class='fa fa-eye-open'></i>已展示</span>";
        } else {
            return "<span style='color: #ff0305;'><i class='fa fa-eye-close'></i>未展示</span>";
        }
    }

    var operateEvents = {
        'click .on': function (e, value, row, index) {
            confirmx(
                    "您确认要展示[" + row.corporationName + "]的成单信息?",
                    function () {
                        var array = [];
                        array.push(row.id);
                        ajaxOnShow(array,"1");
                    });
        },
        'click .off': function (e, value, row, index) {
            confirmx(
                    "您确认要关闭[" + row.corporationName + "]的成单信息?",
                    function () {
                        var ids = [row.id];
                        ajaxOnShow(ids,"0");
                    });
        }
    };

    function operateFormatter(value, row, index) {
        var array = [];
        <shiro:hasPermission name="customer:potentialAfterSalesService:edit">
        if (row.onshow == "1") {
            array.push('<a class="off" href="javascript:void(0);" title="取消展示">');
            array.push('<i class="icon icon-minus-sign"></i>');
            array.push('</a>');
        } else {
            array.push('<a class="on" href="javascript:void(0);" title="展示">');
            array.push('<i class="icon icon-plus-sign"></i>');
            array.push('</a>');
        }
        </shiro:hasPermission>
        return array.join('');
    }

    function ajaxOnShow(ids,onshow){
        $.ajax({
           url: "${ctx}/customer/potentialAfterSalesService/onShow",
           type: "post",
           data: {ids: ids,onshow: onshow},
           dataType: "json",
           success: function (data) {
               if (data.state == true) {
                   showTip(data.message);
                   refresh();
               } else {
                   alertx(data.message);
               }
           },
           error: function (data, state, error) {
               alertx(data.responseText, null, '请求错误');
           }
       });
    }

    $("#open").click(function () {
        var ids = $.map($("#contentTable").bootstrapTable('getSelections'), function (row) {
            return row.id
        });
        if(ids.length<=0){
            alertx("请至少选择一列");
        }else{
            ajaxOnShow(ids,"1");
        }
    });
    $("#close").click(function () {
        var ids = $.map($("#contentTable").bootstrapTable('getSelections'), function (row) {
            return row.id
        });
        if(ids.length<=0){
            alertx("请至少选择一列");
        }else{
            ajaxOnShow(ids,"0");
        }
    });


</script>
</body>
</html>